<template>
  <div class="wrap" ondragstart="return false;" ref="wrap">
    <!-- <img  src="./imgs/bg.png" alt=""> -->
    <div class="inner">
      <img src="./imgs/inner.png" alt="">
      <div class="cont">
        <div class="title">
          <div class="left"></div>
          <div class="right">
            <h3>访问限制</h3>
            <p v-if="ip != ''">您的IP来自: <span>{{ip}} ({{area}})</span></p>
          </div>
        </div>
        <div class="content">
          <p>亲爱的玩家您所在的国家和地区禁止访问我们的网站，</p>
          <p>如果您有疑问，请直接联系我们在线客服，对您造成</p>
          <p>的不便，我们深表歉意。</p>
        </div>
        <div class="btn" @click="goCustemor">在线客服</div>
      </div>
    </div>
    <customer-service class="customer">
      <div class="customer-box">
        <svg-icon icon-class="customer-service" size="medium"></svg-icon>
      </div>
    </customer-service>
  </div>
</template>

<script>
export default {
  name: 'forbidden',
  data() {
    return {
      ip: '',
      area: '',
    };
  },
  methods: {
    goCustemor() {
      this.$global.bus.$emit('open');
    },
    setWrapWidth() {
      const setWidth = () => {
        const width = window.innerWidth;
        const height = window.innerHeight;
        this.$refs.wrap.style.width = width + 'px';
        this.$refs.wrap.style.height = height + 'px';
      };
      setWidth();
      window.addEventListener('resize', setWidth, false);
    }
  },
  mounted() {
    this.setWrapWidth();
    const self = this;
    const Http = new XMLHttpRequest();
    const url = 'https://api.ip.la/cn?json';
    Http.open('GET', url);
    Http.onreadystatechange = function () {
      if (this.readyState === 4 && this.status === 200) {
        self.ip = JSON.parse(Http.responseText).ip;
        self.area = JSON.parse(Http.responseText).location.country_name;
      }
    };
    Http.send();
  },
  destroyed() {
    window.removeEventListener('resize', () => {
    });
  },
};
</script>

<style lang="scss" scoped>
  .wrap {
    width: 100%;
    position: relative;
    min-width: 1450px;
    padding-top: 100px;
    box-sizing: border-box;
    user-select: none;
    background: url('./imgs/bg.png') no-repeat center /cover;

    > img {
      /* position: absolute;
      width:100%;
      left:0;
      top:0; */
    }

    .inner {
      position: relative;

      &::after {
        content: "";
        display: inline-block;
        height: 0;
        line-height: 0;
        visibility: hidden;
        clear: both;
      }

      > img {
        width: 30%;
        float: left;
      }
    }
  }

  .cont {
    float: left;
    padding: 200px 0 0 100px;

    .title {
      display: flex;
      align-items: center;

      .left {
        width: 90px;
        height: 90px;
        background: #1E5ADC;
        border-radius: 50%;
        position: relative;

        &::before {
          content: "";
          position: absolute;
          left: 50%;
          top: 50%;
          transform: translate(-50%, -50%);
          width: 60%;
          height: 10px;
          background: #fff;
        }
      }

      .right {
        padding-left: 35px;

        h3 {
          font-size: 55px;
          margin: 0;
          padding: 0;
        }

        p {
          margin: 0;
          padding: 0;
          font-size: 25px;
          color: #000;

          span {
            color: #1E5ADC;
          }
        }
      }
    }

    .content {
      padding: 60px 0 25px 0;

      p {
        margin: 0;
        padding: 0;
        font-size: 24px;
      }
    }

    .btn {
      width: 266px;
      height: 96px;
      background: url('./imgs/btn.png') no-repeat center /cover;
      font-family: MicrosoftYaHei;
      font-size: 30px;
      color: #FFFFFF;
      letter-spacing: 0;
      text-align: center;
      line-height: 96px;
      cursor: pointer;
      user-select: none;
    }
  }

  .customer {
    position: absolute;
    right: 0;
    bottom: 0;
  }

  .svg-icon--medium {
    width: 0.8rem;
    height: 0.8rem;
    right: 20px;
    bottom: 20px;
  }
</style>
